package ee.reliability.tool.ui.window;

import info.monitorenter.gui.chart.IAxis.AxisTitle;
import info.monitorenter.gui.chart.ZoomableChart;
import info.monitorenter.gui.chart.axis.AxisLinear;
import info.monitorenter.gui.chart.views.ChartPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;

import ee.reliability.tool.ui.AxisScalePolicyFixedTicks;
import ee.reliability.tool.ui.menu.MenuBar;

@SuppressWarnings("serial")
public class MainWindow extends JFrame {

	private static MainWindow myInstance;

	public static MainWindow getInstance(){
		if(myInstance == null)
			myInstance = new MainWindow();
		return myInstance;
	}

	private final ChartPanel chartPanel;
    private final JTable outputDataTable;
	private final JTable statisticDataTable;

	private MainWindow() {
		super("Reliability tool");

		chartPanel = new ChartPanel(new ZoomableChart());
		chartPanel.getChart().setUseAntialiasing(true);
		chartPanel.getChart().getAxisX().setAxisTitle(new AxisTitle("Houts"));
		chartPanel.getChart().getAxisX().setMajorTickSpacing(1);
		chartPanel.getChart().getAxisX().setMinorTickSpacing(10);
		chartPanel.getChart().getAxisX().setStartMajorTick(true);
		chartPanel.getChart().getAxisX().setStartMajorTick(true);
		((AxisLinear)chartPanel.getChart().getAxisX()).setAxisScalePolicy(new AxisScalePolicyFixedTicks());
		chartPanel.getChart().getAxisY().setAxisTitle(new AxisTitle("Reliabilities"));

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setJMenuBar(createJMenuBar());

        JPanel statusBar = new JPanel();
//        statusBar.setLayout(new GridBagLayout());
//        GridBagConstraints gbc = new GridBagConstraints();
        //JLabel statusLabel = new JLabel("Excel info : ");
        outputDataTable = new JTable();
        statisticDataTable = new JTable();
        getOutputDataTable().setShowGrid(true);
        getOutputDataTable().setBackground(Color.WHITE);

        statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
        statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.PAGE_AXIS));
        statusBar.add(getOutputDataTable());
        statusBar.add(statisticDataTable);

        add(statusBar, BorderLayout.SOUTH);
//        add(new Label("File => Load Excel"));

        setPreferredSize(new Dimension(500, 400));
		getContentPane().add(getChartPanel());
        //getContentPane().add(outputDataTable,BorderLayout.SOUTH);
        pack();
        setLocationRelativeTo(null);
	}

	public JMenuBar createJMenuBar() {

    	return new MenuBar();
	}

	public ChartPanel getChartPanel() {
		return chartPanel;
	}

	public JTable getOutputDataTable() {
		return outputDataTable;
	}

	public JTable getStatisticDataTable() {
		return statisticDataTable;
	}
}
